function y = gmm_classify(X, gmm)

num_classes = size(gmm.model, 1);
num_points = size(X, 1);
y = zeros(num_points, 1);

y = y + double(gmm.label(1));
best_logp = gmm_logpdf(X, gmm.model{1}) + log(gmm.prior(1));

for j = 2 : num_classes
    fprintf('Calculating probabilities for class %d\n', gmm.label(j));
    cur_logp = gmm_logpdf(X, gmm.model{j}) + log(gmm.prior(j));
    for i = 1 : num_points
        if (cur_logp(i) > best_logp(i))
            y(i) = gmm.label(j);
            best_logp(i) = cur_logp(i);
        end
    end
end